package com.itheima.test5;

import java.io.*;
import java.net.Socket;

/*
上传图片


接受 服务端给的反馈
 */
public class ClientTest {

    public static void main(String[] args) throws IOException {



        // 创建客户端对象
        Socket socket = new Socket("127.0.0.1", 10001);
        //创建输入流 用来读数据
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("C:\\Users\\Administrator\\Desktop\\美女.jpg"));
        //获取输出流
        OutputStream os = socket.getOutputStream();
        BufferedOutputStream bos = new BufferedOutputStream(os);
        //边读 编写
        byte[] bytes= new byte[1024];
        int len;
        while ((len=bis.read(bytes))!=-1){
            //bytes  0.len
            bos.write(bytes,0,len);
        }
        bos.flush();
        //给服务器一个结束标记
        socket.shutdownOutput();

        //接受服务器的响应
        InputStream is = socket.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        String s = reader.readLine();

        //读 服务器响应的数据
        System.out.println(s);
        // 释放资源
        socket.close();
        bis.close();


    }
}
